package com.chixing.day02;

import java.util.Arrays;

/**
 *数组
 * 引用数据类型的默认值都为null
 */
public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr1 = {10,20,30,40,50};
        int[] arr2 = new int[5];
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]);
        }
        float[] arr3 = {9.9f,4.5f,3.6f,12};
        int arr4[] = {10,20,30};  //C语言写法
        float[] arr5 = new float[5]; //5个0.0
        //arr1 = null; //指针断开

        /*二维数组*/
        int[][] a = {{11,15,17},{21,35,90}}; //2行3列
        System.out.println("a[0][2]:" + a[0][2]);
        System.out.println("a数组的行数: " + a.length);
        System.out.println("a数组的列数: " +a[0].length);
        int[][] b = new int[2][3];

   /*     //错误的定义
        int[][] c = new int[2][];
        System.out.println("c数组的行数: " + c.length);
        c[0][0] =1; //错误*/

        /*数组的工具类:Arrays*/
      int[] newArr =  Arrays.copyOf(arr1,10);
      for (int i =0;i <newArr.length;i++){
          System.out.print(newArr[i] + "," );
      }
      System.out.println("\n=========");


      //三目运算
        int x = 11;
        int y = 20;
        int z = (x > y) ? y : x;
        System.out.println(z);
    }
}
